package look_and_feel; /**
 * Date: Feb 20, 2009
 * Time: 1:04:13 AM
 * To change this template use File | Settings | File Templates.
 *
 * @author Jose Martin Rozanec;
 */

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.api.renderers.SubstanceDefaultComboBoxRenderer;
import org.jvnet.substance.skin.SkinInfo;
import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

/**
 * Test application that shows the use of the
 * {@link SubstanceLookAndFeel#getAllSkins()} API.
 *
 * @author Kirill Grouchnikov
 * @see SubstanceLookAndFeel#getAllSkins()
 */
public class GetAllSkins extends JFrame {
    /**
     * Creates the main frame for <code>this</code> sample.
     */
    public GetAllSkins() {
        super("Get all skins");

        setLayout(new BorderLayout());

        final JPanel panel = new JPanel(new FlowLayout());
        // Get all skins and set the vector as a model
        // for combobox.
        final JComboBox cb = new JComboBox(new Vector<SkinInfo>(
                SubstanceLookAndFeel.getAllSkins().values()));
        cb.setRenderer(new SubstanceDefaultComboBoxRenderer(cb) {
            @Override
            public Component getListCellRendererComponent(JList list,
                                                          Object value, int index, boolean isSelected,
                                                          boolean cellHasFocus) {
                SkinInfo si = (SkinInfo) value;
                return super.getListCellRendererComponent(list, si
                        .getDisplayName(), index, isSelected, cellHasFocus);
            }
        });
        panel.add(new JLabel("All skins:"));
        panel.add(cb);

        this.add(panel, BorderLayout.CENTER);

        this.setSize(400, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * The main method for <code>this</code> sample. The arguments are
     * ignored.
     *
     * @param args Ignored.
     * @throws Exception If some exception occured. Note that there is no special
     *                   treatment of exception conditions in <code>this</code>
     *                   sample code.
     */
    public static void main(String[] args) throws Exception {
        UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
        JFrame.setDefaultLookAndFeelDecorated(true);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new GetAllSkins().setVisible(true);
            }
        });
    }
}
